package com.beiye.drivertransport.utils;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.beiye.drivertransport.SubActivity.ImageLookActivity;
import com.beiye.drivertransport.SubActivity.PreviewImgActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Copyright (C)
 * FileName: ImageJavascriptInterface
 * Author: 刘学章
 * Date: 2020/8/27 11:48
 * Description: JS交互
 */
public class ImageJavascriptInterface {
    private Context context;
    private String[] imageUrls;
    private ArrayList<String> imgLists;

    public ImageJavascriptInterface(Context context, String[] imageUrls) {
        this.context = context;
        this.imageUrls = imageUrls;

        imgLists=new ArrayList<>();
        for(int i=0;i<imageUrls.length;i++){
            imgLists.add(imageUrls[i]);
        }
    }
    //java回调js代码，不要忘了@JavascriptInterface这个注解，不然点击事件不起作用
    @JavascriptInterface
    public void openImage(String img,int pos) {
        /*Intent intent = new Intent(context, PreviewImgActivity.class);//改为你要跳转的页面
        Bundle bundle = new Bundle();
        bundle.putString("imgUrl",img);
        intent.putExtras(bundle);
        context.startActivity(intent);*/

        Intent intent = new Intent(context, ImageLookActivity.class);//改为你要跳转的页面
        Bundle bundle = new Bundle();
        intent.putExtra("position",(pos+1));
        intent.putExtra("imgs",imgLists);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }
}
